package com.orhon.smartcampus.modules.systemctl.mutation;

import com.orhon.smartcampus.basicComponents.Result;
import com.orhon.smartcampus.modules.systemctl.dao.OrgDepartmentUserRelationDao;
import com.orhon.smartcampus.utils.ObjectToMap;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.HashMap;

@Component
public class DeleteDepartmentUserMutation implements DataFetcher {
    
    @Autowired
    OrgDepartmentUserRelationDao orgDepartmentUserRelationDao;

    /**
     * 删除人员分配记录
     * editor : ths
     */
    @Override
    public Object get(DataFetchingEnvironment environment) throws Exception {
        if (environment.containsArgument("condition")) {
            HashMap<String,Object> map = ObjectToMap.to(environment.getArgument("condition"));
            String sql = "update OrgDepartmentUserRelation set deleted_at = Now() where systemctlOrgDepartmentsByDepartmentId = "+map.get("department_id")+" and systemctlOrgDutiesByDutyId = "+map.get("duty_id")+" and userUsersByUserId = "+map.get("user_id");
            orgDepartmentUserRelationDao.updateHql(sql);
            return Result.ok();
        }
        return Result.error();
    }
}

